package com.xm.xmapp;

import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.xm.xmapp.app.MyAppcation;
import com.xm.xmapp.base.BaseActivity;
import com.xm.xmapp.myinterface.DisssmissInterFace;
import com.xm.xmapp.myinterface.GetDataInterFace;
import com.xm.xmapp.request.bean.Alter_user_passwordRequest;
import com.xm.xmapp.tools.Des4;
import com.xm.xmapp.tools.StringTools;
import com.xm.xmapp.tools.Tools;

public class UpPassWordActivity extends BaseActivity implements OnClickListener {

	private TextView oldpassword, newpassword, newpassword1;
	private TextView queren;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_uppassword);
	}

	@Override
	public void initView() {

		oldpassword = (TextView) findViewById(R.id.oldpassword);
		newpassword = (TextView) findViewById(R.id.newpassword);
		newpassword1 = (TextView) findViewById(R.id.newpassword1);
		queren = (TextView) findViewById(R.id.queren);
	}

	@Override
	public void initData() {
		setMyTitle("修改登录密码");
	}

	@Override
	public void initEvent() {
		queren.setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {

		switch (v.getId()) {
		case R.id.queren:

			if (!StringTools.isLength(oldpassword.getText().toString(), 6)) {
				Tools.showMessage("原密码至少为6位");
			} else if (!StringTools.isLength(newpassword.getText().toString(), 6)) {
				Tools.showMessage("密码至少为6位");
			} else if (!newpassword.getText().toString().equals(newpassword1.getText().toString())) {
				Tools.showMessage("两次输入密码不同");
			} else {
				alter_user_passwordRequest();
			}

			break;
		default:
			break;
		}
	}

	private void alter_user_passwordRequest() {

		Alter_user_passwordRequest requestBean = new Alter_user_passwordRequest();
		requestBean.old_password = Des4.encode(oldpassword.getText().toString());
		requestBean.new_password = Des4.encode(newpassword.getText().toString());
		promptDialog.show();
		MyAppcation.getMyAppcation().getPostData(this, requestBean, new GetDataInterFace<String>() {

			@Override
			public void onResponse(String response) {

				promptDialog.dismiss();
				Tools.showMessage("修改成功");
				finish();

			}
		}, new DisssmissInterFace() {

			@Override
			public void putError(VolleyError error) {

				promptDialog.dismiss();
			}
		});
	}

}
